package com.sai.tool;
import android.view.ViewGroup;
import android.graphics.Typeface;
import android.app.Activity;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
import android.widget.EditText;

public class FontManager
{
	public Typeface tf = null;
	public Activity act = null;
	public String path = null;
	
	public FontManager(Activity act, String path){
		this.act = act;
		this.path = path;
		
		tf = getTypeface();
	}

    public void changeFonts(ViewGroup root)
	{
		int i;
		tf = getTypeface();
		
		for (i = 0; i < root.getChildCount(); i++)
		{  
			View v = root.getChildAt(i);  
			if (v instanceof TextView)
			{  
				((TextView) v).setTypeface(tf);  
			}
			else if (v instanceof Button)
			{  
				((Button) v).setTypeface(tf);  
			}
			else if (v instanceof EditText)
			{  
				((EditText) v).setTypeface(tf);  
			}
			else if (v instanceof ViewGroup)
			{  
				changeFonts((ViewGroup) v);  
			}  
		} 
		
		
    }
	
	Typeface getTypeface()
	{
		if (tf == null)
			tf = Typeface.createFromAsset(this.act.getAssets(), this.path);  
		return tf;
	}
}  
